package com.aos.erp.gov.ex.web.rest;

import com.aos.erp.common.bean.ResultEntity;
import com.aos.erp.common.utils.DateUtils;
import com.aos.erp.common.utils.NumUtil;
import com.aos.erp.gov.ex.enums.RegisterTaskType;
import com.aos.erp.gov.ex.model.dto.CheckResultFailDTO;
import com.aos.erp.gov.ex.model.ro.AddStudentExamRo;
import com.aos.erp.gov.ex.model.ro.AddStudentFieldRo;
import com.aos.erp.gov.ex.model.ro.FieldStatus;
import com.aos.erp.gov.ex.service.GovExRegisterTaskService;
import com.aos.erp.gov.ex.service.remote.StudentExamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Slf4j
@RestController("GovTestController")
@RequestMapping("/api/gov/test")
@Api("GovTestController")
public class GovTestController {

    @Resource
    private GovExRegisterTaskService exRegisterTaskService;
    @Resource
    private StudentExamService examService;


    @GetMapping("/submitted")
    @ApiOperation(value = "提交成功")
    public ResultEntity submitted(String idnum) {
        exRegisterTaskService.saveSubmitted(idnum,RegisterTaskType.api,true);
        return ResultEntity.success();
    }


    @GetMapping("/success")
    @ApiOperation(value = "测试审批成功")
    public ResultEntity success(String idnum) {
        exRegisterTaskService.saveConfirmSuccess(idnum,RegisterTaskType.api,true);
        return ResultEntity.success();
    }


    @GetMapping("/failed")
    @ApiOperation(value = "测试审批失败")
    public ResultEntity failed(String idnum,String message) {
        CheckResultFailDTO dto=new CheckResultFailDTO();
        dto.setIdNo(idnum);
        dto.setSerialNumber(RandomUtils.nextInt()+"");
        dto.setFeedbackResult(message);
        dto.setApplyTime(DateUtils.toDate("2018-10-16"));
        exRegisterTaskService.saveConfirmFailed(dto,RegisterTaskType.api,true);
        return ResultEntity.success();
    }



    @GetMapping("/yukao")
    @ApiOperation(value = "约考")
    public ResultEntity yukao(String idnum,int km,long schoolId) {
        List<AddStudentExamRo> roList = new ArrayList<AddStudentExamRo>(1);

        AddStudentExamRo bean = new AddStudentExamRo();
        bean.setDriverId(schoolId);
        bean.setName("测试的默认名称");
        bean.setExamSubject(km);
        bean.setExamCarModel("C1");
        bean.setExamReadyTime(DateUtils.toDate("2018-11-22"));
        bean.setExamTime(DateUtils.toDate("2018-11-29"));
        bean.setExamAddress("测试考点");
        bean.setExamRound("第二轮");
        roList.add(bean);
        examService.addStudentExamYK(roList);

        return ResultEntity.success();
    }

    @GetMapping("/chengji")
    @ApiOperation(value = "返回成绩")
    public ResultEntity chengji(String name,int km,int score,long schoolId) {
        List<AddStudentFieldRo> roList = new ArrayList<AddStudentFieldRo>(1);

        AddStudentFieldRo bean = new AddStudentFieldRo();
        bean.setDriverId(schoolId);
        bean.setName(name);
        bean.setExamSubject(km);
        bean.setExamCarModel("C1");
        bean.setExamTime(DateUtils.toDate("2018-11-29"));
        bean.setExamAddress("测试考点");
        bean.setExamRound("第二轮");
        bean.setExamField("" + score);

        bean.setFieldStatus(score >= 90 ? FieldStatus.ok : FieldStatus.fail);

        roList.add(bean);
        examService.addStudentExamResult(roList);

        return ResultEntity.success();
    }

}